package dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    //传递的数据总条数
    private int count;
    //消息提示
    private String msg;
    //传递的数据
    private Object data;
    //状态码  0代表成功  -1代表失败
    private int code;
    //是否成功
    private boolean success;

    public static Result ok(){
        Result result = new Result();
        result.code = 0;
        result.success = true;
        result.msg = "操作成功";
        return result;
    }

    public static Result fail(){

        Result result = new Result();
        result.code = -1;
        result.success = false;
        result.msg = "操作失败";
        return result;
    }

    public Result code(int code){
        this.code = code;
        return this;
    }

    public Result msg(String msg){
        this.msg = msg;
        return this;
    }

    public Result data(Object data){
        this.data = data;
        return this;
    }

    public Result count(int count){
        this.count = count;
        return this;
    }
}
